#include <iostream>
#include <fstream>
using namespace std;

// 文件的位置指示器 seek tell

// 文件输入流 
void test1(){
    ifstream ifs("num.txt");
    if(!ifs.good()){
        cerr << "ifstream in not good" << endl;
        return;
    }
    // 从文件的某个位置开始读数据
    int bgindext = 4;//设置在下标为4的位置开始读数据
    int bg_indext = ifs.tellg(bgindext);
    cout << "bg_indext:" << bg_indext << endl;
    int ed_idext = ifs.seekg(0,std::ios::end);//从0开始找到文件末尾的位置
    cout << "ed_idext:" << ed_idext << endl;

    string  word;
    for(int i = bg_indext; i < ed_idext; i++){
            ifs >> word;
            cout << word << " ";
    }

}

//文件输出流
void test2(){
    ofstream ofs("num2.txt");
    // 写入数据到文件num2.txt中
    int num;
    for(int i = 0; i < 5; i++){
        cin >> num;
        ofs << num << " ";
    }
    int now_indext = ofs.tellp();
    cout << "now_indext；" << now_indext << endl;
    int indext = ofs.seekp(0, std::ios::end);
    cout << "indext" << indext << endl;
}

int main(int atgc, char * argv[])
{
    test1();
    test2();
    return 0;
}

